import { createRouter, createWebHistory } from 'vue-router'

const Home = () => import('@/views/home')
const Category = () => import('@/views/category')
const Profile = () => import('@/views/profile')
const ShopCart = () => import('@/views/shopcart')
const Detail = () => import('@/views/detail')
const Register = () => import('@/views/profile/Register')
const Login = () => import('@/views/profile/Login')
const Collects = () => import('@/views/profile/components/Collects')
const Address = () => import('@/views/profile/components/Address')
const Orders = () => import('@/views/order')
const CreateOrder = () => import('@/views/order/components/CreateOrder')

const routes = [
  {
    path: '/',
    component: Home,
    meta: {
      title: 'ewshop-home'
    }
  }, {
    path: '/home',
    component: Home,
    meta: {
      title: 'ewshop-home'
    }
  }, {
    path: '/category',
    component: Category,
    meta: {
      title: 'ewshop-category'
    }
  }, {
    path: '/profile',
    component: Profile,
    meta: {
      title: 'ewshop-profile'
    }
  }, {
    path: '/shopcart',
    component: ShopCart,
    meta: {
      title: 'ewshop-shopcart'
    }
  }, {
    path: '/detail',
    component: Detail,
    meta: {
      title: 'ewshop-detail'
    }
  }, {
    path: '/register',
    component: Register,
    meta: {
      title: 'ewshop-register'
    }
  }, {
    path: '/login',
    component: Login,
    meta: {
      title: 'ewshop-login'
    }
  }, {
    path: '/collects',
    component: Collects,
    meta: {
      title: 'ewshop-collects'
    }
  }, {
    path: '/address',
    component: Address,
    meta: {
      title: 'ewshop-address'
    }
  }, {
    path: '/orders',
    component: Orders,
    meta: {
      title: 'ewshop-orders'
    }
  }, {
    path: '/preview',
    component: CreateOrder,
    meta: {
      title: 'ewshop-createOrder'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 前置守卫
router.beforeEach((to, from, next) => {
  next()
  document.title = to.meta.title
})

export default router
